/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package compiler.scanner;

import compiler.grammar.Terminal;
import compiler.scanner.dfa.DFAGen;
import compiler.scanner.dfa.DFAState;
import compiler.scanner.dfa.DFATable;
import compiler.scanner.nfa.ETransition;
import compiler.scanner.nfa.NFAState;
import compiler.scanner.nfa.NFATransition;
import java.util.ArrayList;

/**
 *
 * @author meemo
 */
public class NfaToDfaAdapter
{
    //~ Instance fields --------------------------------------------------------

    private DFAState dfaMini = null;
    private DFAState dfaNormal = null;
    private DFATable dfaTable = null;
    private NFAState nfaMachine = null;

    //~ Constructors -----------------------------------------------------------

    public NfaToDfaAdapter(ArrayList<Terminal> terminals)
    {
        // to create the DFA of the entire symbols
        NFAState root = new NFAState();

        for (Terminal t : terminals)
        {
            // add E-transition for each RE from the root
            NFATransition transToThisNfa = new ETransition();
            root.getTransitions().add(transToThisNfa);
            transToThisNfa.getDestinations().add(t.getNFAStart());
        }

        DFAGen dfa = new DFAGen(root);
        dfaNormal  = dfa.getNormalDfa();
        dfaMini    = dfa.getMinimizedDfa();
        dfaTable   = new DFATable(dfaMini);
        nfaMachine = root;
    }

    //~ Methods ----------------------------------------------------------------

    public DFAState getDfaMini()
    {
        return dfaMini;
    }

    public DFAState getDfaNormal()
    {
        return dfaNormal;
    }

    public DFATable getDfaTable()
    {
        return dfaTable;
    }

    public NFAState getNfaMachine()
    {
        return nfaMachine;
    }
}
